//
//  HomeDiscountVIew.m
//  phmall
//
//  Created by admin on 2017/10/28.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "HomeDiscountVIew.h"

@implementation HomeDiscountVIew

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.headView=[[UIImageView alloc]init];
        [self addSubview:self.headView];
        
        self.advertisement=[[UIImageView alloc]init];
        self.advertisement.userInteractionEnabled=YES;
        [self addSubview:self.advertisement];
        UITapGestureRecognizer *advertisementTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(advertisementTap:)];
        [self.advertisement  addGestureRecognizer:advertisementTap];
        
        self.groupBuying=[[UIImageView alloc]init];
        self.groupBuying.userInteractionEnabled=YES;
        [self addSubview:self.groupBuying];
        UITapGestureRecognizer *groupBuyingTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(groupBuyingTap:)];
        [self.groupBuying  addGestureRecognizer:groupBuyingTap];
        
        self.auction=[[UIImageView alloc]init];
        self.auction.userInteractionEnabled=YES;
        [self addSubview:self.auction];
        UITapGestureRecognizer *auctionTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(auctionTap:)];
        [self.auction  addGestureRecognizer:auctionTap];
        
        self.integral=[[UIImageView alloc]init];
        self.integral.userInteractionEnabled=YES;
        [self addSubview:self.integral];
        UITapGestureRecognizer *integralTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(integralTap:)];
        [self.integral  addGestureRecognizer:integralTap];
        
        self.across=[[UIView alloc]init];
        self.across.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self addSubview:self.across];
        
        self.vertical=[[UIView alloc]init];
        self.vertical.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [self addSubview:self.vertical];
    }
    return self;
}
-(void)advertisementTap:(UITapGestureRecognizer *)tap{
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectAtImage:andIndex:)]) {
        [self.delegate selectAtImage:self andIndex:1];
    }
}
-(void)groupBuyingTap:(UITapGestureRecognizer *)tap{
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectAtImage:andIndex:)]) {
        [self.delegate selectAtImage:self andIndex:2];
    }
}
-(void)auctionTap:(UITapGestureRecognizer *)tap{
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectAtImage:andIndex:)]) {
        [self.delegate selectAtImage:self andIndex:3];
    }
}
-(void)integralTap:(UITapGestureRecognizer *)tap{
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectAtImage:andIndex:)]) {
        [self.delegate selectAtImage:self andIndex:4];
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.offset(40);
    }];
    
    [self.advertisement mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self);
        make.width.offset(SCREEN_WIDTH*3/7);
        make.top.equalTo(self.headView.mas_bottom);
    }];
    
    [self.groupBuying mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.advertisement.mas_right);
        make.right.equalTo(self);
        make.top.equalTo(self.headView.mas_bottom);
        make.bottom.equalTo(self.advertisement.mas_centerY);
    }];
    
    [self.auction mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.advertisement.mas_right);
        make.right.equalTo(self.groupBuying.mas_centerX);
        make.top.equalTo(self.advertisement.mas_centerY);
        make.bottom.equalTo(self);
    }];

    [self.integral mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.auction.mas_right);
        make.right.equalTo(self.groupBuying);
        make.top.equalTo(self.advertisement.mas_centerY);
        make.bottom.equalTo(self);
    }];
    
    [self.across mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.advertisement.mas_right);
        make.right.equalTo(self.groupBuying);
        make.height.offset(1);
        make.centerY.equalTo(self.advertisement);
    }];
    
    [self.vertical mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(1);
        make.centerX.equalTo(self.across);
        make.top.equalTo(self.across);
        make.bottom.equalTo(self);
    }];
}
@end
